package com.congee02.bt.dfs.top2bottom;

import com.congee02.bt.TreeNode;

public class MinDepth {

    public int minDepth(TreeNode root) {

        if (root == null) {
            return 0;
        }

        return help(root);
    }

    private int help(TreeNode root) {

        if (root == null) {
            return 300001;
        }

        if (root.left == null && root.right == null) {
            return 1;
        }

        return 1 + Math.min(
                help(root.left),
                help(root.right)
        );
    }

}
